﻿using markdown_picture_packer.common.constants;
using markdown_picture_packer.common.utils;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace markdown_picture_packer.frontend.panels
{
    public class ProgressBarPanel : BasePanel
    {
        private Label TitleLb;
        private ProgressBar Pb;
        private Label ValueLb;
        private int MaxValue;

        public override void InitComponent()
        {
            TitleLb = new Label { Text = "执行进度", Font = Constants.EXECUTE_FONT, TextAlign = ContentAlignment.MiddleCenter };
            Pb = new ProgressBar();
            ValueLb = new Label { Font = Constants.EXECUTE_FONT, TextAlign = ContentAlignment.MiddleCenter };
        }
        public override void InitSize(int newWdith, int newHeight)
        {
            TitleLb.Size = new Size(65, newHeight);
            ValueLb.Size = new Size(90, newHeight);
            Pb.Size = new Size(FrontUtil.GetFillWidth(newWdith, TitleLb, ValueLb), newHeight);
        }
        public override void InitLocation()
        {
            TitleLb.Location = new Point(0, 0);
            FrontUtil.OnRight(Pb, TitleLb, 0);
            FrontUtil.OnRight(ValueLb, Pb, 0);
        }
        public override void AddComponent()
        {
            Controls.Add(TitleLb);
            Controls.Add(Pb);
            Controls.Add(ValueLb);
        }
        public void PlusValue()
        {
            if (Pb.Value < MaxValue) Pb.Value++;
            ValueLb.Text = Pb.Value >= MaxValue ? "执行完成" : $"{Pb.Value}/{MaxValue}";
        }

        public bool IsFinished()
        {
            return Pb.Value == MaxValue;
        }
        public void SetMaxValue(int maxValue)
        {
            MaxValue = maxValue;
            Pb.Maximum = MaxValue;
            Pb.Value = 0;
            ValueLb.Text = $"0/{MaxValue}";
        }
    }
}
